package com.yu.app.controller;

import com.yu.app.pojo.Address;
import com.yu.app.service.impl.AddressServiceImpl;
import com.yu.app.common.annotation.NeedLogin;
import com.yu.common.exception.ServiceException;
import com.yu.common.util.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "收获地址")
@RestController
@RequestMapping("/api-app/address")
public class AddressController {
    @Resource
    private AddressServiceImpl addressService;


    @ApiOperation("地址的详细信息")
    @GetMapping("/{addressId}")
    public R<Address> getAddressDetail(@ApiParam("地址id") @PathVariable Integer addressId) {
        return R.ok(addressService.getAddressDetail(addressId));
    }

    @ApiOperation("添加用户收获地址")
    @NeedLogin
    @PostMapping("")
    public R<Integer> addUserAddress(@RequestBody Address address) throws ServiceException {
        return R.ok(addressService.addUserAddress(address));
    }

    @ApiOperation("更新用户收获地址")
    @NeedLogin
    @PutMapping("")
    public R<Integer> updateUserAddress(@RequestBody Address address) {
        return R.ok(addressService.updateUserAddress(address));
    }

}

